<?php require_once(dirname(__FILE__)."/../config/config.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册/修改店铺</title>
</head>
<body>
<?php  
if($_SESSION['admin_name']=="")
{

	echo "<script>location.href='admin_login.php';</script>";
}
?>
<?php  //添加LOGO
function upload_image($imgpath)
     {
       $name=$imgpath["name"];
       $tmp_name=$imgpath["tmp_name"];
	$filetype = pathinfo($name, PATHINFO_EXTENSION);//获取后缀
       $size=$imgpath["size"];
	   $filename=date("YmdHis",time()).rand(1000,9999).".".$filetype;
	   $filepath="/userfiles/shoplogo/".$filename;
       $uploadfile = "../userfiles/shoplogo/".$filename;
     
	 
    if(move_uploaded_file($tmp_name,$uploadfile))
         return $filepath; 
  }
 ?>
 <?php
 if($_FILES['logo']['size']>0){
 $logo=$_FILES['logo'];
 $logo=upload_image($logo);
 }else{
 	$logo=$_REQUEST['logo1'];
 }
?>
<?php
	$shop_id = $_GET['id'];
	$sql1 = "select * from zy_shop where shop_id= '".$shop_id."'";
	$result = mysql_query($sql1);
	$shop = mysql_fetch_array($result);
	if($shop > 0)
	{
		echo "<h1 align='center'>店铺信息修改</h1>";
	}
	else
	{
		echo "<h1 align='center'>注册新店铺</h1>";
	}
?>
<?php    //店铺注册、修改
	if(!empty($_POST['Submit'])){
			$shop_name=$_POST['shop_name'];
			$shop_address=$_POST['shop_address'];
			$shop_phone=$_POST['shop_phone'];
			$description=$_POST['description'];
			$introduction=$_POST['introduction'];
			$announce=$_POST['announce'];
			$start_price=$_POST['start_price'];
			$surcharge=$_POST['surcharge'];
			$district=$_POST['district'];
			$distance=$_POST['distance'];
			$opening_hours=$_POST['opening_hours'];
			$delivery_time=$_POST['delivery_time'];
			$delivery_long=$_POST['delivery_long'];
			$shop_type=$_POST['shop_type'];
			$shop_type=implode("|", $shop_type);
			$create_user=$_SESSION['admin_name'];
			$update_user=$_SESSION['admin_name'];
		if($shop_name!="" && $shop_address!="" && $shop_phone!="" && $description!="" && $introduction!="" && $announce!="" && $start_price!="" && $distance!="" && $opening_hours!="" && $delivery_time!="" && $delivery_long!=""){
			if($shop_id>0){
				$sql = "update zy_shop set shop_name= '".$shop_name."',shop_address='".$shop_address."',shop_phone='".$shop_phone."',logo='".$logo."',description='".$description."',introduction='".$introduction."',announce='".$announce."',start_price='".$start_price."',surcharge='".$surcharge."',district='".$district."',distance='".$distance."',opening_hours='".$opening_hours."',delivery_time='".$delivery_time."',delivery_long='".$delivery_long."',shop_type='".$shop_type."',create_time=NOW(),update_user='".$create_user."' where shop_id='".$shop_id."'";
				mysql_query($sql);
				echo "<script>alert('修改成功！');location.href='admin_management.php';</script>";
			}else{
				$sql="insert into zy_shop(shop_name,shop_address,shop_phone,logo,description,join_time,introduction,announce,start_price,district,distance,opening_hours,delivery_time,delivery_long,shop_type,remark,is_delete,create_user,create_time,update_user,update_time) values('$shop_name','$shop_address','$shop_phone','$logo','$description',NOW(),'$introduction','$announce','$start_price','$district','$distance','$opening_hours','$delivery_time','$delivery_long','$shop_type','null',0,'$create_user',NOW(),'$update_user',NOW())";
				mysql_query($sql);
				echo "<script>alert('注册成功！');location.href='admin_management.php';</script>";
			}
		}else{
			echo "请确认填写正确！";
		}
	}
?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return Checker()">
  <table width="500" height="30" align="center" border="1">
    <tr>
      <td width="200" height="30" align="center">店铺名称</td>
      <td width="300" height="30" align="center">	  
		  <input name="shop_name" type="text" id="shop_name" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["shop_name"];?>"<?php } ?>/>
		  <?php
		  	if($shop_id>0){
		  ?>
		  <td width="200" height="30" align="center">LOGO<br />
	   <img name="logo" src="<?php echo SITE_ROOT;?><?php echo $shop['logo'];?>" width="121" height="107" alt="" /></td><?php }?>
	  </td>
    </tr>
    <tr>
      <td width="200" height="30" align="center">店铺地址</td>
      <td width="300" height="30" align="center">
		  <input name="shop_address" type="text" id="shop_address"
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["shop_address"];?>"<?php } ?>/>
	  </td>
    </tr>
	<tr>
      <td width="200" height="30" align="center">店铺电话</td>
      <td width="300" height="30" align="center">
		  <input name="shop_phone" type="text" id="shop_phone"
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["shop_phone"];?>"<?php } ?>/>
	  </td>
    </tr>
	<tr>
      <td width="200" height="30" align="center">logo</td>
      <td width="300" height="30" align="center">
	  <input type="hidden" name="logo1" value="<?php echo $shop['logo'];?>" />
	  <input name="logo" type="file" id="logo" />
	   </td>
	</tr>
	<tr>
      <td width="200" height="30" align="center">店铺描述</td>
      <td width="300" height="30" align="center">
		  <input name="description" type="text" id="description" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["description"];?>"<?php } ?>/>
	  </td>
    </tr>
	<tr>
      <td width="200" height="30" align="center">店铺简介</td>
      <td width="300" height="30" align="center">
		  <input name="introduction" type="text" id="introduction" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["introduction"];?>"<?php } ?>/>
	  </td>
    </tr>
    <tr>
      <td width="200" height="30" align="center">店内公告</td>
      <td width="300" height="30" align="center">
		  <input name="announce" type="text" id="announce" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["announce"];?>"<?php } ?>/>
	  </td>
    </tr>
    <tr>
      <td width="200" height="30" align="center">起送价格</td>
      <td width="300" height="30" align="center">
		  <input name="start_price" type="text" id="start_price" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["start_price"];?>"<?php } ?>/>
	  </td>
    </tr>
	<tr>
      <td width="200" height="30" align="center">外卖费用</td>
      <td width="300" height="30" align="center">
		  <input name="surcharge" type="text" id="surcharge" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["surcharge"];?>"<?php } ?>/>
	  </td>
    </tr>
    <tr>
      <td width="200" height="30" align="center">商圈范围</td>
      <td width="300" height="30" align="center">
	  <?php 
	  	$sql3="select * from zy_businessarea where level=3";
		$rs=mysql_query($sql3);
	  ?>
	  <select name="district">
	  <?php while($city=mysql_fetch_array($rs)){
	  		  if($shop_id>0){
	  ?>
	    <option <?php echo $shop['district']==$city['id']?'selected':'' ?> 
		value="<?php echo $city['id'];?>" >
		<?php echo $city['name'];?>
		</option>
		<?php }else{?>
	    <option value="<?php echo $city['id'];?>"><?php echo $city['name'];?></option>
		<?php } }?>
      </select>
      </td>
    </tr>
    <tr>
      <td width="200" height="30" align="center">商圈距离</td>
      <td width="300" height="30" align="center">
		  <input name="distance" type="text" id="distance" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["distance"];?>"<?php } ?>/>
	  </td>
    </tr>
    <tr>
      <td width="200" height="30" align="center">营业时间</td>
      <td width="300" height="30" align="center">
		  <input name="opening_hours" type="text" id="opening_hours" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["opening_hours"];?>"<?php } ?>/>
	  </td>
    </tr>
    <tr>
      <td width="200" height="30" align="center">送餐时间</td>
      <td width="300" height="30" align="center">
		  <input name="delivery_time" type="text" id="delivery_time" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["delivery_time"];?>"<?php } ?>/>
	  </td>
    </tr>
	<tr>
      <td width="200" height="30" align="center">送餐时长</td>
      <td width="300" height="30" align="center">
		  <input name="delivery_long" type="text" id="delivery_long" 
		  <?php if($shop_id>0){ ?> 
		  value="<?php echo $shop["delivery_long"];?>"<?php } ?>/>
	  </td>
    </tr>
	<tr>
	<td width="200" height="30" align="center">餐厅类型</td>
      <td width="300" height="30" align="center">
	  <input type="checkbox" class="checkbox" name="shop_type[]" value="[a1]" <?php if(strpos($shop['shop_type'],"a1")){?> checked <?php }?>/>本周推荐
	  <input type="checkbox" class="checkbox" name="shop_type[]" value="[a2]" <?php if(strpos($shop['shop_type'],"a2")!=false){?> checked <?php }?>/>江浙菜
	  <input type="checkbox" class="checkbox" name="shop_type[]" value="[a3]" <?php if(strpos($shop['shop_type'],"a3")!=false){?> checked <?php }?>/>快餐小吃
	  <input type="checkbox" class="checkbox" name="shop_type[]" value="[a4]" <?php if(strpos($shop['shop_type'],"a4")!=false){?> checked <?php }?>/>日韩料理
	  <input type="checkbox" class="checkbox" name="shop_type[]" value="[a5]" <?php if(strpos($shop['shop_type'],"a5")!=false){?> checked <?php }?>/>川菜
	  <input type="checkbox" class="checkbox" name="shop_type[]" value="[a6]" <?php if(strpos($shop['shop_type'],"a6")!=false){?> checked <?php }?>/>奶茶甜点
	  </td>
	</tr>
  </table>
  <h3 align="center">
  <?php
  if($shop_id>0){
  ?>
    <input type="submit" name="Submit" value="修改"/>
   <?php 
   }else{
   ?>
   	<input type="submit" name="Submit" value="注册"/>
	<?php }
	?>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="admin_management.php">返回</a>
  </h3>
</form>
</body>
</html>
